import request from "../utils/request";

// 获取文章列表
export function getArticleList(data = {}) {
  return request({
    url: '/article/api/portalArticleList',
    method: 'POST',
    data
  })
}

// 根据文章ID获取文章信息
export function articleInfo(id) {
  return request({
    url: `/article/api/info/${id}`,
    method: 'GET'
  })
}

// 获取排行榜的文章
export function getViewsArticle() {
  return request({
    url: `/article/api/getViewsArticle`,
    method: 'GET'
  })
}

// 获取当前文章的上一篇和下一篇
export function getNextAndPreviousArticle(articleId) {
  return request({
    url: `/article/api/getNextAndPreviousArticle/${articleId}`,
    method: 'GET'
  })
}

// 获取最新文章列表
export function getNewsArticleList() {
  return request({
    url: `/article/api/getNewArticleList`,
    method: 'GET'
  })
}

// 获取推荐文章
export function recommendArticle(articleId) {
  return request({
    url: `/article/api/getRecommendArticle/${articleId}`,
    method: 'GET'
  })
}

// 文章浏览量
export function articleViews(articleId) {
  return request({
    url: `/article/api/article_views/${articleId}`,
    method: 'GET'
  })
}



// 收藏文章
export function collectArticle(data = {}) {
  return request({
    url: `/article/favorite`,
    method: 'POST',
    data
  })
}

// 分类列表
export function categoryList() {
  return request({
    url: `/article/api/category/category_list`,
    method: 'GET'
  })
}

// 根据分类ID查询分类信息
export function categoryInfo(categoryId) {
  return request({
    url: `/article/api/category/info/${categoryId}`,
    method: 'GET'
  })
}

// 根据分类ID查询分类信息
export function getArticlesByCategoryId(data = {}) {
  return request({
    url: `/article/api/getByCategoryId`,
    method: 'POST',
    data
  })
}

// 获取用户的文章数、分类数
export function getArticleCategoryNums(userId) {
  return request({
    url: `/article/api/getArticleCategoryNums`,
    method: 'GET',
    params: {
      userId
    }
  })
}

// 获取用户的文章
export function getUserArticle(data = {}) {
  return request({
    url: `/article/api/getUserArticle`,
    method: 'POST',
    data
  })
}

// 根据用户ID获取分类信息列表
export function getCategoryByUserId(data = {}) {
  return request({
    url: `/article/api/category/getCategoryByUserId`,
    method: 'POST',
    data
  })
}

// 根据分类ID获取标签ID
export function getLabelByCategoryId(categoryId) {
  return request({
    url: `/article/api/label/getByCategoryId/${categoryId}`,
    method: 'GET'
  })
}

// 创建文章
export function createArticle(data) {
  return request({
    url: '/article/create',
    method: 'post',
    data
  })
}

// 获取门户端用户个人基本信息
export function getUserBaseInfo(userId) {
  return request({
    url: `/article/api/getUserBaseInfo`,
    method: 'GET',
    params: {
      userId
    }
  })
}

// 根据文章ID删除文章
export function deleteArticle(articleId) {
  return request({
    url: `/article/delete/${articleId}`,
    method: 'delete'
  })
}

// 编辑文章信息
export function updateArticle(data) {
  return request({
    url: '/article/update',
    method: 'put',
    data
  })
}

// 获取内容管理中的文章列表
export function getContentManageArticleList(data) {
  return request({
    url: '/article/list',
    method: 'post',
    data
  })
}

// 获取用户的文章列表
export function getUserArticleList(title = '') {
  return request({
    url: '/article/getUserArticleList',
    method: 'GET',
    params: {
      title
    }
  })
}

// 记录用户浏览文章历史
export function recordUserBrowseArticle(data = {}) {
  return request({
    url: `/article/recordUserBrowseArticle`,
    method: "POST",
    data
  });
}

// 获取用户的浏览文章历史记录
export function getUserBrowseArticle(data = {}) {
  return request({
    url: `/article/api/getUserBrowseArticle`,
    method: "POST",
    data
  });
}
